
#include "../includes.h"

// in 100ns scale
#define TRAIM_ALARM_LIMIT	6


char Setting_LEAPSEC();

void EB_Task_start();
char EB_self_test();
char EB_set();
char EB_almanac();
void init_OEMV_Log(int fd);

int sync_al_duration = 0;

int init_eb_timeout=0;
unsigned char tod_status = 0;
int k_once_cnt=0;

void Init_EB(char mode, char times, char no_alarm)
{
	int i;

	init_OEMV_Log(fdEB);	//sewon

	SYSTEM.EB.bRcvZDA = 0;
	SYSTEM.EB.zero_tracking = 0;
	SYSTEM.EB.once_receiver_detect = 0;
	SYSTEM.EB.model_cnt = 0;
	SYSTEM.EB.prevTODSec = 0;
	if(k_once_cnt++<1)
	{
		SYSTEM.EB.print_Flag 	= 0;
		SYSTEM.EB.command_Flag 	= 0;
	}

	if( times!=INIT_EB_NOT_RESET ) issue_f1000c_cold_start();

	for( i = 0; i < 15; i++ ){
		SYSTEM.EB.MODEL[i] = (char)0;
		SYSTEM.EB.SERIAL[i] = (char)0;
	}

	for( i = 0; i < 11; i++ ){
		SYSTEM.EB.SWVER[i] = (char)0;
		SYSTEM.EB.SWREV[i] = (char)0;
		SYSTEM.EB.SWDATE[i] = (char)0;
	}
	
	SYSTEM.EB.SUBID				= 0;

	SYSTEM.EB.STATUS 			= EB_STATUS_NONE;


	SYSTEM.EB.TASK				= OFF;
	SYSTEM.EB.DIAG				= UNDEFINED;

	SYSTEM.EB.ID				= UNDEFINED;	// UT or UT-PLUS
    SYSTEM.EB.LOCKMODE         	= EB_UNLOCKED;  /* Locked, Unlocked */
    SYSTEM.EB.SELFTEST         	= UNDEFINED;
    SYSTEM.EB.PSDM             	= UNDEFINED;
    SYSTEM.EB.SATSTATUS			= UNDEFINED;
    SYSTEM.EB.PHM              	= UNDEFINED;
    SYSTEM.EB.LEAPSECOND		= 0;
    SYSTEM.EB.LEAPSECPENDING   	= UNDEFINED;
    

	if(mode == INIT_EB_LOUD) {
    	SYSTEM.EB.ANTENNA          	= UNDEFINED;
    	SYSTEM.EB.PrevANTENNA      	= UNDEFINED;
    }

	SYSTEM.EB.LockCheck			= UNDEFINED;

	SYSTEM.EB.antenna_fault_counter = 0;

	SYSTEM.EB.settodefault		= UNDEFINED;

	//SYSTEM.EB.ANTDLY			= 99999;
	SYSTEM.EB.ANTDLY			= 120;
    SYSTEM.EB.TIMEMODE 			= UNDEFINED;
    SYSTEM.EB.LOCALHOUR 		= UNDEFINED;
    SYSTEM.EB.LOCALMINUTE 		= UNDEFINED;

    SYSTEM.EB.PHP.STEP 			= disablePHM;
    SYSTEM.EB.PHP.Counter 		= 0;
    SYSTEM.EB.PHP.TryCounter	= 0;


	SYSTEM.EB.rxflag = OFF;
	SYSTEM.EB.RxCounter = 0;
	SYSTEM.EB.RxCheckCounter = -1;

    for(i = 0; i < 10; i++){
        SYSTEM.EB.AntennaFaultTable[i] = 0;
    }

	// Event
    SYSTEM.EB.PHP_Enable 	= OFF;
    SYSTEM.EB.PHM_Disable 	= OFF;
    SYSTEM.EB.EB_Default 	= OFF;

    /* SYSTEM->TRACK */
    SYSTEM.TRACK.DOP = 0;
    if(times == INIT_EB_FIRST) {
    	SYSTEM.TRACK.DOPTYPE = 0;
    	reset_eb_counter();
    }
    SYSTEM.TRACK.VISIBLE = 0;
    SYSTEM.TRACK.TRACKED = 0;


    for(i = 0; i < 8; i++){         /* 8 channel E/B */
        SYSTEM.TRACK.SAT[i].ID = 0;
        SYSTEM.TRACK.SAT[i].SS = 0;
    }

	for( i = 0; i < 12; i++ ){
		SYSTEM.TRACK.VIS_SAT[i].ID = 0;
		SYSTEM.TRACK.VIS_SAT[i].EL = 0;
		SYSTEM.TRACK.VIS_SAT[i].AZ = 0;
		SYSTEM.TRACK.VIS_SAT[i].HEALTH = 0;
		SYSTEM.TRACK.PRN_USED[i]=0;
	}

	for(i = 0;i < 8; i++){
		SYSTEM.TRACK.satmonitor[i] = 0;
	}

	SYSTEM.EB.UnlockedCounter = 0;
	SYSTEM.EB.UnlockedDelayCounter = 0;

	SYSTEM.EB.LockedCounter_1 	= 0;
	SYSTEM.EB.UnlockedCounter_1 = 0;

	SYSTEM.EB.TRAIM.T_LIMIT		= TRAIM_ALARM_LIMIT;

	SYSTEM.EB.TRAIM.FLAG 		= OFF;

	SYSTEM.EB.TRAIM.LIMIT		= 0;
	SYSTEM.EB.TRAIM.CTRLMODE 	= 0;

	SYSTEM.EB.TRAIM.PULSE 		= 0;
	SYSTEM.EB.TRAIM.PULSESYNC 	= 0; // 0:UTC 1:GPS

	SYSTEM.EB.TRAIM.SOL_STATUS 	= 2; // 0: OK
									 // 1: Alarm
									 // 2: Unknown

	SYSTEM.EB.TRAIM.STATUS 		= 2; // 0: detection and isolation
									 // 1: detection only
									 // 2: neither
	SYSTEM.EB.TRAIM.ACCURACY 	= 0; // estimatation of 1pps
	SYSTEM.EB.TRAIM.SAWTOOTH 	= 0;
	
	eb_10min_start = 0;
	freq_stable_cnt=0;
	freq_stable_enough = NO;
	bResetReceiver = 1;
	last_init_eb = GC.RunningTime;
	
	SYSTEM.TRACK.MASK = 0;
	if(no_alarm == YES) {
		init_eb_timeout = 1;
		tod_status = (TOD.status&BIT_STATUS_GPS_FAIL)&0xFF;
	}

	SYSTEM.EB.model_name=NULL;
}

//int init_eb2_timeout=0;
//unsigned char tod_status2 = 0;
//int k_once_cnt2=0;
void Init_EB2(char mode, char times, char no_alarm)// OEMV1-Rcv-Data		sewon
{
	int i;

	init_OEMV_Log(fdEB2);	//sewon

	SYSTEM.EB2.bRcvZDA = 0;
	SYSTEM.EB2.zero_tracking = 0;
	SYSTEM.EB2.once_receiver_detect = 0;
	SYSTEM.EB2.model_cnt = 0;
	SYSTEM.EB2.prevTODSec = 0;
	SYSTEM.EB2.print_Flag = 0;
	SYSTEM.EB2.command_Flag = 0;

//	if( times!=INIT_EB_NOT_RESET ) issue_f1000c_cold_start();

	for( i = 0; i < 15; i++ ){
		SYSTEM.EB2.MODEL[i] = (char)0;
		SYSTEM.EB2.SERIAL[i] = (char)0;
	}

	for( i = 0; i < 11; i++ ){
		SYSTEM.EB2.SWVER[i] = (char)0;
		SYSTEM.EB2.SWREV[i] = (char)0;
		SYSTEM.EB2.SWDATE[i] = (char)0;
	}

	SYSTEM.EB2.SUBID				= 0;

	SYSTEM.EB2.STATUS 			= EB_STATUS_NONE;


	SYSTEM.EB2.TASK				= OFF;
	SYSTEM.EB2.DIAG				= UNDEFINED;

	SYSTEM.EB2.ID				= UNDEFINED;	// UT or UT-PLUS
    SYSTEM.EB2.LOCKMODE         	= EB_UNLOCKED;  /* Locked, Unlocked */
    SYSTEM.EB2.SELFTEST         	= UNDEFINED;
    SYSTEM.EB2.PSDM             	= UNDEFINED;
    SYSTEM.EB2.SATSTATUS			= UNDEFINED;
    SYSTEM.EB2.PHM              	= UNDEFINED;
    SYSTEM.EB2.LEAPSECOND		= 0;
    SYSTEM.EB2.LEAPSECPENDING   	= UNDEFINED;


	if(mode == INIT_EB_LOUD) {
    	SYSTEM.EB2.ANTENNA          	= UNDEFINED;
    	SYSTEM.EB2.PrevANTENNA      	= UNDEFINED;
    }

	SYSTEM.EB2.LockCheck			= UNDEFINED;

	SYSTEM.EB2.antenna_fault_counter = 0;

	SYSTEM.EB2.settodefault		= UNDEFINED;

	//SYSTEM.EB2.ANTDLY			= 99999;
	SYSTEM.EB2.ANTDLY			= 120;
    SYSTEM.EB2.TIMEMODE 			= UNDEFINED;
    SYSTEM.EB2.LOCALHOUR 		= UNDEFINED;
    SYSTEM.EB2.LOCALMINUTE 		= UNDEFINED;

    SYSTEM.EB2.PHP.STEP 			= disablePHM;
    SYSTEM.EB2.PHP.Counter 		= 0;
    SYSTEM.EB2.PHP.TryCounter	= 0;


	SYSTEM.EB2.rxflag = OFF;
	SYSTEM.EB2.RxCounter = 0;
	SYSTEM.EB2.RxCheckCounter = -1;

    for(i = 0; i < 10; i++){
        SYSTEM.EB2.AntennaFaultTable[i] = 0;
    }

	// Event
    SYSTEM.EB2.PHP_Enable 	= OFF;
    SYSTEM.EB2.PHM_Disable 	= OFF;
    SYSTEM.EB2.EB_Default 	= OFF;

    /* SYSTEM->TRACK */
    SYSTEM.TRACK2.DOP = 0;
    if(times == INIT_EB_FIRST) {
    	SYSTEM.TRACK2.DOPTYPE = 0;
//    	reset_eb_counter();
    }
    SYSTEM.TRACK2.VISIBLE = 0;
    SYSTEM.TRACK2.TRACKED = 0;


    for(i = 0; i < 8; i++){         /* 8 channel E/B */
        SYSTEM.TRACK2.SAT[i].ID = 0;
        SYSTEM.TRACK2.SAT[i].SS = 0;
    }

	for( i = 0; i < 12; i++ ){
		SYSTEM.TRACK2.VIS_SAT[i].ID = 0;
		SYSTEM.TRACK2.VIS_SAT[i].EL = 0;
		SYSTEM.TRACK2.VIS_SAT[i].AZ = 0;
		SYSTEM.TRACK2.VIS_SAT[i].HEALTH = 0;
		SYSTEM.TRACK2.PRN_USED[i]=0;
	}

	for(i = 0;i < 8; i++){
		SYSTEM.TRACK2.satmonitor[i] = 0;
	}

	SYSTEM.EB2.UnlockedCounter = 0;
	SYSTEM.EB2.UnlockedDelayCounter = 0;

	SYSTEM.EB2.TRAIM.T_LIMIT		= TRAIM_ALARM_LIMIT;

	SYSTEM.EB2.TRAIM.FLAG 		= OFF;

	SYSTEM.EB2.TRAIM.LIMIT		= 0;
	SYSTEM.EB2.TRAIM.CTRLMODE 	= 0;

	SYSTEM.EB2.TRAIM.PULSE 		= 0;
	SYSTEM.EB2.TRAIM.PULSESYNC 	= 0; // 0:UTC 1:GPS

	SYSTEM.EB2.TRAIM.SOL_STATUS 	= 2; // 0: OK
									 // 1: Alarm
									 // 2: Unknown

	SYSTEM.EB2.TRAIM.STATUS 		= 2; // 0: detection and isolation
									 // 1: detection only
									 // 2: neither
	SYSTEM.EB2.TRAIM.ACCURACY 	= 0; // estimatation of 1pps
	SYSTEM.EB2.TRAIM.SAWTOOTH 	= 0;

//	eb_10min_start = 0;
//	freq_stable_cnt=0;
//	freq_stable_enough = NO;
//	bResetReceiver = 1;
//	last_init_eb = GC.RunningTime;

//	SYSTEM.TRACK2.MASK = 0;
//	if(no_alarm == YES) {
//		init_eb2_timeout = 1;
//		tod_status2 = (TOD.status&BIT_STATUS_GPS_FAIL)&0xFF;
//	}

	SYSTEM.EB2.model_name=NULL;
}



void EB_Task_start()
{
	SYSTEM.EB.TASK 				= ON;
	SYSTEM.EB.STATUS 			= EB_STATUS_SELFTEST;

	SYSTEM.EB.set_step 			= SET_START;
	SYSTEM.EB.ID 				= UNDEFINED;

	SYSTEM.EB.almanac_step 		= EB_SET_PSDM;
	SYSTEM.EB.IntervalCounter 	= 0;

	SYSTEM.EB.LockedCounter 	= 0;

	sync_al_duration = 0;

	//reset_eb_counter();
}


void EB_Task()
{
	if(SYSTEM.EB.STATUS == EB_STATUS_NONE){
	    if((SYSTEM.EB.rxflag == OK) && (SYSTEM.EB.RxCounter >= 5)){

	    	EB_Task_start();
			MessageOut((BYTE*)"GPS Receiver - in\r\n");
	    }

        SetPSDM(ENABLE);
	}

	SYSTEM.EB.rxflag = OFF;
	SYSTEM.EB.RxCheckCounter++;

	switch(SYSTEM.EB.STATUS){

		case	EB_STATUS_SELFTEST:
				if (EB_self_test() == OK) {
					SYSTEM.EB.STATUS = EB_STATUS_ALMANAC;
                    SYSTEM.EB.PSDM  = UNDEFINED;
                    //hmlee - no "break" !!
				}
				else{
					break;
				}

		case	EB_STATUS_ALMANAC:
				if (EB_almanac() == OK) {
					SYSTEM.EB.STATUS = EB_STATUS_SET;
					//hmlee - no "break" !!
				}
				else{
					break;
				}

		case	EB_STATUS_SET:
				if (EB_set() == OK) {
					if(skipping_change_eb){skipping_change_eb = 1;}
					SYSTEM.EB.STATUS = EB_STATUS_RUN;
					SYSTEM.EB.TASK = OFF;
					SYSTEM.EB.LockedCounter = 0;

					SYSTEM.EB.once_receiver_detect = ON;

					MessageOut("EB-RUN\r\n");
					LogIt(LOG_CATA1_NORM, LOG_CATA2_NOTHING, LOG_EB_In,0);
				}
				break;
		default:
				SYSTEM.EB.TASK = OFF;
				break;
	}
}



char EB_self_test()
{
	SYSTEM.EB.IntervalCounter++;

	if (SYSTEM.EB.IntervalCounter == 1){

		MessageOut("Self test wait seconds..\r\n");
		RequestEB(eSELFTEST);
	}
    else if(SYSTEM.EB.IntervalCounter == 10){

		SYSTEM.EB.IntervalCounter = 0;

		if(SYSTEM.EB.SELFTEST == OK){
    		MessageOut("E/B OK!\r\n");
    		return OK;
		}
		else if(SYSTEM.EB.SELFTEST == FAIL){
			SYSTEM.EB.SELFTEST = FAIL;
    		MessageOut("E/B FAIL\r\n");
		}
		else {
    		// Communication Fail!!!
    		SYSTEM.EB.SELFTEST = COM_FAIL;
    		MessageOut("retry\r\n");
		}
	}
	
	return NO;
}



char EB_set()
{
    switch(SYSTEM.EB.set_step){

		case	SET_START:
                    SYSTEM.EB.set_step = SET_SATSTATUS;
					//break;

		case	SET_SATSTATUS:
					if( Enable_SATSTATUS() == OK ){
						SYSTEM.EB.set_step = SET_MASK;
						//hmlee - no "break" !!
					}
					else{
						break;
					}

		case	SET_MASK:
					if( Enable_MASK() == OK ){
						SYSTEM.EB.set_step = SET_TRAIM;
						//hmlee - no "break" !!
					}
					else{
						break;
					}

		case	SET_TRAIM:
					if(Enable_TRAIM() == OK){
						SYSTEM.EB.set_step = SET_Position;
						//hmlee - no "break" !!
					}
					else{
						break;
					}
					
        case    SET_Position:
                    if( Setting_POSITION() == OK ){
                    	SYSTEM.EB.set_step = SET_TimeMode;
                    	//hmlee - no "break" !!
                    }
                    else{
                    	break;
                    }
					
		case	SET_TimeMode:
					if( Setting_TIMEMODE() == OK ){
                    	SYSTEM.EB.set_step = SET_GmtOffset;
                    	//hmlee - no "break" !!
					}
					else{
						break;
					}

        case    SET_GmtOffset:
                    if( Setting_GMTOFFSET() == OK ){
                        SYSTEM.EB.set_step = SET_Antdly;
                        //hmlee - no "break" !!
                    }
                    else{
                    	break;
                    }

        case    SET_Antdly:
                    if( Setting_ANTDLY() == OK ){
                        SYSTEM.EB.RxCheckCounter = 0;
						SYSTEM.EB.UnlockedDelayCounter = 60;
						return OK;
                    }
                    break;
/*
        case    SET_Delay:
                    if( SYSTEM.EB.IntervalCounter++ == 60 ){
                        SYSTEM.EB.RxCheckCounter = 0;
						return OK;
                    }
                    break;
*/
    }
    return NO;
}


char EB_almanac()
{
	int i;
	char msg[20];


	SYSTEM.EB.IntervalCounter++;

    switch(SYSTEM.EB.almanac_step){

        case    EB_SET_PSDM:
                    if( Enable_PSDM() == OK ){
                    	SYSTEM.EB.almanac_step = EB_SET_EB_ID;
                    	SYSTEM.EB.IntervalCounter = 0;
                    	
                    	//hmlee - disable position hold
                    	SYSTEM.EB.PHM_Disable = ON;
                    	//hmlee - no "break" !!
                    }
                    else{
                    	break;
                    }

		case	EB_SET_EB_ID:
					if ( Setting_EBID() == OK ) {
                        SYSTEM.EB.almanac_step = EB_SET_ALMANAC;
                        
                        //hmlee - disable position hold again
                    	SYSTEM.EB.PHM_Disable = ON;
                        //hmlee - no "break" !!
                    }
                    else{
						break;
					}

		case	EB_SET_ALMANAC:

                    if( !(SYSTEM.TRACK.STATUS & 0x01) /*&& (SYSTEM.EB.LOCKMODE != EB_UNLOCKED)*/ /* && (LockCounter == 10)*/) { /* good almanac */

                        MessageOut("ALMANAC GOOD\r\n");
						SYSTEM.EB.almanac_step = EB_SET_LEAPSECOND;
                    }
                    else {
                    	sync_al_duration++;
                    	if(sync_al_duration>40*60){
                    		sync_al_duration = 0;
                    		LogIt3(LOG_CATA1_NORM, LOG_CATA2_NOTHING, 
                    			LOG_SYNC15_RESET, RESET_MODEL_SYNC15, RESET_TYPE_ALMCLEAR, 4);
                    		RequestEB(eDEFAULT);
                    		
                    		Init_EB(INIT_EB_SILENT, INIT_EB_SECOND, YES);
							EB_Task_start();
                    	}

                        if (SYSTEM.IO.CTRL_PORT.MODE == UDEBUG){
							for( i = 7, msg[0] = (char)0; i >= 0; i-- ){
								if ( (SYSTEM.TRACK.STATUS >> i) & 0x01 ) {	strcat(msg,"1");}
								else {									strcat(msg,"0");}
							}
							sprintf((char*)MESG,"DOP:%d type:%d V:%d T:%d Status: %s\r\n",SYSTEM.TRACK.DOP,SYSTEM.TRACK.DOPTYPE,SYSTEM.TRACK.VISIBLE,SYSTEM.TRACK.TRACKED,msg);
                            TransmitMessage((BYTE*)MESG,DEBUG_PORT);
                        }
                    }
					break;


		case	EB_SET_LEAPSECOND:
		            if( Setting_LEAPSEC() == OK ){	
		            	return OK;	
		            }
					break;
	}

	return FAIL;
}



/* ---------------------------------------------------------------------
Last Updated  : Tue  09-02-97 11:59:47
Function Name : Init_LEAPSEC
Description   : Calculate LeapSecond by comparison of GPS, UTC time
                final state -> GPS referenced time
Variables     : STARTUP.LEAP.GPSTIME, STARTUP.LEAP.UTCTIME, STARTUP.LEAP.START, STARTUP.LEAP.END
Return Values : Success -> OK!
--------------------------------------------------------------------- */
//
//====================================================
//
//  UT-Plus oncore !!!!!!!!
//====================================================
char Setting_LEAPSEC()
{

	//if ( SYSTEM.EB.LEAPSECOND == 0 ) {
	if ( SYSTEM.EB.LEAPSECOND < 13) {
		SetUTCOFFSET(POLL);

       	if(SYSTEM.IO.CTRL_PORT.MODE == UDEBUG){
        	sprintf((char*)MESG,"LEAPSECOND:%d retry..\r\n",SYSTEM.EB.LEAPSECOND);
            TransmitMessage((BYTE*)MESG,DEBUG_PORT);
        }

		return NO;
	}
	
	if(SYSTEM.EB.LEAPSECPENDING == UNDEFINED){
		SetLEAPSECOND(POLL);
		
		if(SYSTEM.IO.CTRL_PORT.MODE == UDEBUG){
        	sprintf((char*)MESG,"LEAPSECOND PENDING:%d retry..\r\n",SYSTEM.EB.LEAPSECPENDING);
            TransmitMessage((BYTE*)MESG,DEBUG_PORT);
        }
		return NO;
	}

	//else if (SYSTEM.EB.LEAPSECOND >= 13 ) {
	
   	if(SYSTEM.IO.CTRL_PORT.MODE == UDEBUG){
		sprintf((char*)MESG,"LEAPSECOND:%d, LEAPSECOND PENDING:%d\r\n",
    		SYSTEM.EB.LEAPSECOND, SYSTEM.EB.LEAPSECPENDING);
    	TransmitMessage((BYTE*)MESG,DEBUG_PORT);
	}
	
	SYSTEM.TIME.LEAPSECOND = SYSTEM.EB.LEAPSECOND;
	SYSTEM.TIME.LEAPSECPENDING = SYSTEM.EB.LEAPSECPENDING;
		
	return YES;
}

//int OEMV_init_count = 0;
void init_OEMV_Log(int fd)		//sewon,12-05-02
{
	char buf[100];

//	if( fd == fdEB ) 			OEMV_init_count++;
//	else if( fd == fdEB2 )		OEMV_init_count++;
//
//	if( OEMV_init_count > 2 )	return;

	//===Serial Baudrate Initialize===//
	if( fd == fdEB ){
		set_tty( fd, B9600, 1 );
		sprintf(buf,"COM COM1 115200 N 8 1 N OFF ON\r\n");
		write(fd,buf,strlen(buf));
		set_tty( fd, B115200, 1 );
	}
	else if( fd == fdEB2 ){
		set_tty( fd, B9600, 2 );
		sprintf(buf,"COM COM1 115200 N 8 1 N OFF ON\r\n");
		write(fd,buf,strlen(buf));
		set_tty( fd, B115200, 2 );
	}

	sprintf(buf,"UNLOGALL\r\n");
	write(fd,buf,strlen(buf));

	if( fd == fdEB )	// OEMV-2
	{
		//10Mhz External External Clock Enable//
		sprintf(buf,"CLOCKADJUST DISABLE\r\n");
		write(fd,buf,strlen(buf));
		sprintf(buf,"EXTERNALCLOCK RUBIDIUM 10MHZ\r\n");
		write(fd,buf,strlen(buf));

		//LOG DATA ENABLE//
		sprintf(buf,"LOG TIMEA ONTIME 1\r\n");
		write(fd,buf,strlen(buf));
		sprintf(buf,"LOG RANGEA ONTIME 5\r\n");
		write(fd,buf,strlen(buf));
		sprintf(buf,"LOG SATXYZA ONTIME 5\r\n");
		write(fd,buf,strlen(buf));
		sprintf(buf,"LOG GPGGA ONTIME 1\r\n");
		write(fd,buf,strlen(buf));
		sprintf(buf,"LOG GPZDA ONTIME 1\r\n");
		write(fd,buf,strlen(buf));
		sprintf(buf,"LOG GPGSA ONTIME 1\r\n");
		write(fd,buf,strlen(buf));
		sprintf(buf,"LOG GPGSVA ONTIME 1\r\n");
		write(fd,buf,strlen(buf));

	}
	if( fd == fdEB2 )	// OEMV-1DF
	{
		//ALIGN AUTOMATION Rover Receiver//
		sprintf(buf,"ALIGNAUTOMATION ENABLE COM2 230400 10 ON\r\n");
		write(fd,buf,strlen(buf));

		//ALIGN LOG PRINT//
		sprintf(buf,"LOG GPHDT ONCHANGED\r\n");
		write(fd,buf,strlen(buf));
		return;
	}
	//ALIGN AUTOMATION Rover Receiver//
	sprintf(buf,"MOVINGBASESTATION ENABLE\r\n");
	write(fd,buf,strlen(buf));
	//ALIGN THRESHOLD//
	sprintf(buf,"HDTOUTTHRESHOLD 2.0\r\n");
	write(fd,buf,strlen(buf));

	//Satellite Cutoff Angle//
	sprintf(buf,"ECUTOFF 20.0\r\n");
	write(fd,buf,strlen(buf));
	CONFIG.MASK = 20.0;
	CONFIG.WriteEvent = ON;

	sprintf(buf,"SAVECONFIG\r\n");
	write(fd,buf,strlen(buf));


}
